package bairui.international.console.web.controller.order.product;

/**
 * @see bairui.international.console.web.controller.order.product.Page_BaseFilter
 *
 */
class Page_Filter

{
	
	/**
	 * 过滤扩展接口
	 */
	static interface FilterExtends {
		com.querydsl.core.types.Predicate gainUserName(
			String userName
		);
	}
	
	final static com.querydsl.core.BooleanBuilder query(
		bairui.international.model.domain.jpa.QTB_ProductOrder QRoot,
		javax.servlet.http.HttpServletRequest request
		,FilterExtends filterExtends
	) {
		com.querydsl.core.BooleanBuilder query = query(
				QRoot
	,			com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("number"), 
						String.class, 
						"yyyy-MM-dd"
					)
	,			com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("type"), 
						bairui.international.model.type.Type_ProductOrder.class, 
						"yyyy-MM-dd"
					)
	,			com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("state"), 
						bairui.international.model.status.State_ProductOrder.class, 
						"yyyy-MM-dd"
					)
	,			(null==request.getParameter("branchCompany.id"))
					? null
					: new bairui.international.model.domain.jpa.TB_BranchCompany(com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("branchCompany.id"), 
						Long.class, 
						"yyyy-MM-dd"
					))
	,			(null==request.getParameter("area.id"))
					? null
					: new bairui.international.model.domain.jpa.TB_Town(com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("area.id"), 
						Long.class, 
						"yyyy-MM-dd"
					))
	,			com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("payWay"), 
						bairui.international.model.type.Type_ProductOrderPay.class, 
						"yyyy-MM-dd"
					)
	,			com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("submitDate_start"), 
						java.util.Date.class, 
						"yyyy-MM-dd"
					),
				com.sh_lianjing.string.util.Util_String.parseToType(
						request.getParameter("submitDate_end"), 
						java.util.Date.class, 
						"yyyy-MM-dd"
					)
			);
			/* comment 附加过滤属性 */
			if(null != request.getParameter("userName")){
				query.and(filterExtends.gainUserName(
					com.sh_lianjing.string.util.Util_String.parseToType(
							request.getParameter("userName"), 
							String.class, 
							"yyyy-MM-dd"
						)
				));
			}
	;
		return query;
	}
	
	final static com.querydsl.core.BooleanBuilder query(
		bairui.international.model.domain.jpa.QTB_ProductOrder QRoot
	,	String number
	,	bairui.international.model.type.Type_ProductOrder type
	,	bairui.international.model.status.State_ProductOrder state
	,	bairui.international.model.domain.jpa.TB_BranchCompany branchCompany
	,	bairui.international.model.domain.jpa.TB_Town area
	,	bairui.international.model.type.Type_ProductOrderPay payWay
	,	java.util.Date submitDate_start,
		java.util.Date submitDate_end
	) {
		com.querydsl.core.BooleanBuilder builder = new com.querydsl.core.BooleanBuilder();
	
		if(null != number){
			builder.and(QRoot.number.like("%"+number+"%"));
		}
		if(null != type){
			builder.and(QRoot.type.eq(type));
		}
		if(null != state){
			builder.and(QRoot.state.eq(state));
		}
		if(null != branchCompany){
			builder.and(QRoot.branchCompany.eq(branchCompany));
		}
		if(null != area){
			builder.and(QRoot.area.eq(area));
		}
		if(null != payWay){
			builder.and(QRoot.payWay.eq(payWay));
		}
		if(null != submitDate_start && null != submitDate_end){
			builder.and(QRoot.submitDate.between(submitDate_start, submitDate_end));
		}
		return builder;
	}
	
}
